package com.example.api.controller;

import com.example.api.aspect.SystemControllerLog;
import com.example.api.model.entity.Vehicle;
import com.example.api.model.enums.ActionTypeEnum;
import com.example.api.model.support.RespBean;
import com.example.api.service.VehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "车辆管理")
@RestController
@RequestMapping("/api/vehicle")
public class VehicleController {

    @Resource
    private VehicleService vehicleService;

    @ApiOperation("添加车辆")
    @PostMapping("/")
    @SystemControllerLog(description = "添加车辆", actionType = ActionTypeEnum.CREATE)
    public RespBean save(@RequestBody Vehicle vehicle) {
        return vehicleService.save(vehicle);
    }

    @ApiOperation("查询车辆")
    @GetMapping("/")
    @SystemControllerLog(description = "查询车辆", actionType = ActionTypeEnum.QUERY)
    public List<Vehicle> findAll() {
        return vehicleService.findAll();
    }

    @ApiOperation("根据id查询车辆")
    @GetMapping("/{id}")
    @SystemControllerLog(description = "根据id查询车辆", actionType = ActionTypeEnum.QUERY)
    public Vehicle findById(@PathVariable Integer id) {
        return vehicleService.findById(id);
    }

    @ApiOperation("删除车辆")
    @DeleteMapping("/{id}")
    @SystemControllerLog(description = "删除车辆", actionType = ActionTypeEnum.DELETE)
    public RespBean delete(@PathVariable Integer id) {
        return vehicleService.delete(id);
    }

}
